package mvc.bezier;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;

import org.geom.Point2D;
import org.geom.Point3D;
import org.geom.curve.ICurve;
import org.render.IRenderer;

import mvc.model.ModelCurve;
import mvc.view.ViewCurve;

public class ViewCurveBezier2D extends ViewCurve { private static final long serialVersionUID = 1L;

	public ViewCurveBezier2D(ModelCurve model, IRenderer r, Dimension d,
			String title) {
		super(model, r, d, title);
	}
	
	@Override
	public void render(ICurve curve, Graphics g) {
		drawControlPoints(g);
		super.render(curve, g);
	
	}
	
	private void drawControlPoints(Graphics g) {
		ArrayList<Point3D> controlPoints = ((IModelBezier)model).getControlPoints();
		Point2D p2;
		Point2D p2pre = renderer.transform3dTo2d(controlPoints.get(0));
	
		for( Point3D p3 : controlPoints) {
			p2 = renderer.transform3dTo2d(p3);
			drawPoint(g, p2, p2pre);
			p2pre = p2;
		}
	}
	
	private void drawPoint(Graphics g, Point2D p, Point2D pre) {
		int tx = (int)getTranslate().x;
		int ty = (int)getTranslate().y;
	
		int k = 8;
	
		g.setColor(new Color(192, 192, 192));
		g.drawLine( 
				(int)pre.x + tx, 
				(int)pre.y + ty, 
				(int)p.x   + tx, 
				(int)p.y   + ty );
	
		g.setColor(new Color(127, 193, 232));
		g.fillOval((int)p.x +tx-k/2, 
				(int)p.y +ty-k/2, 
				k, k);
	
	}
	

}
